import React from 'react';
import {inject, observer} from 'mobx-react';
import {
    WeaLocaleProvider,
    WeaErrorPage,
    WeaTools
} from 'ecCom'

const getLabel = WeaLocaleProvider.getLabel;

@inject('GrabSingleStore')
@observer
class GrabSingle extends React.Component {
    constructor(props) {
        super(props);
    }
    componentDidMount() {//一些初始化请求
    }
    componentWillReceiveProps(nextProps) {
    }

    componentWillUnmount() {
        //组件卸载时一般清理一些状态
    }

    onMouseOver = ()=>{
        document.querySelector('.btn').setAttribute("class", "mouseover btn")
    }
    onMouseLeave = () =>{
        document.querySelector('.btn').setAttribute("class", "btn")
    }
    onGrabSingle(){
        const { GrabSingleStore } = this.props;
        GrabSingleStore.grabSingle();
    }
    render() {
        return (
            <div style={{width: '100%',textAlign: 'center'}}>
                <div className={'btn'} onMouseOver={()=>{this.onMouseOver()}}
                     onMouseLeave={()=>{this.onMouseLeave()}}
                     onClick={()=>{this.onGrabSingle()}}
                >{getLabel(381925, "抢单")}</div>
            </div>
        );
    }
}

//组件检错机制
class MyErrorHandler extends React.Component {
    render() {
        const hasErrorMsg = this.props.error && this.props.error !== "";
        return(
            <WeaErrorPage msg={ hasErrorMsg ? this.props.error : getLabel(384697, "对不起，该页面异常，请联系管理员！") } />
        );
    }
}



GrabSingle = WeaTools.tryCatch( React, MyErrorHandler, { error: "" })(GrabSingle);


export default GrabSingle